﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StartupTaskRunner.Configuration;
using StartupTaskRunner.Logging;

namespace StartupTaskRunner.Actions
{
    public class CopyAction : ActionBase
    {
        public override string Type
        {
            get { return "Copy"; }
        }

        public override void Execute()
        {
            IStorageDAL storageDal = StorageDALFactory.GetStorageDAL();

            string container = this.ContainerName;
            string blobResource = this.SourceFile;
            string destinationFolder = this.DestinationLocation;

            // Determine blob container
            if(string.IsNullOrWhiteSpace(container))
            {
                container = ConfigType.GetBlobStorage().defaultContainer;
            }

            //TODO: currently not suporting destination location: downlaod all to current location
            if(!string.IsNullOrWhiteSpace(destinationFolder))
            {
                destinationFolder = Environment.CurrentDirectory;
            }

            Logger.WriteMessage("Copy resource from blob storage");
            Logger.WriteMessage("\tDestination folder: {0}", Environment.CurrentDirectory);
            Logger.WriteMessage("\tDownload from container: {0}", container);
            Logger.WriteMessage("\tDownloading resource: {0}", blobResource);
            Logger.WriteMessage("\tApply overwrite: {0}", Overwrite.ToString());
            storageDal.DownloadFileFromBlob(Environment.CurrentDirectory, container, blobResource, this.Overwrite);
        }

        public string ContainerName {get; set;}

        public string SourceFile { get; set; }

        public string DestinationLocation { get; set; }

        public bool Overwrite { get; set; }
    }
}
